package io_demo.serializable_demo;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
 * @author ChenYongHao
 * @date 2023/4/28 10:53
 * @desc 对象序列化流
 */
class Student implements Serializable {
    private static final long serialVersionUID = 5923003911550370832L;
    private String name;
    private Integer age;

    public Student() {
        super();
    }

    public Student(String name, Integer age) {
        super();
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student [name=" + name + ", age=" + age + "]";
    }
}

public class xlh_Serializable_demo {
    public static void main(String[] args) throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:\\cyhKyGit\\Java_Study\\Java_File_IO\\src\\main\\java\\io_demo\\serializable_demo\\xlh4.txt"));

        Student s = new Student("曹晨磊", 30);
        oos.writeObject(s);

        oos.close();
    }
}
